import React, {useState} from "react";
import CityHeader from "../../components/PubHeader";
import CurrentCity from "./CurrentCIty";
import CityList from "./CityList";
import {useSelector,useDispatch} from "react-redux";
import {changeCity} from "../../redux/actions/city";
import CityLists from "./CityLists";
const City=(props)=>{
    //订单一个state将从cityList那获取到的city传入到CurrentCity中
    // const[city,setCityState]=useState('北京')

    //使用react获取
    const city=useSelector(state => state.city)

    const dispatch=useDispatch()

    //作为CItyList的父组件，定义一个函数，获取到city
    function onCityEvent(city){
        // console.log(city)
        // setCityState(city)
        dispatch(changeCity(city))
        //回退到首页
        window.history.back()

    }
    return(
        <div>
            <CityHeader/>
            <CurrentCity city={city.cityName}/>
            <CityList onEvent={onCityEvent}/>
            <CityLists onEvent={onCityEvent}/>
         </div>
    )
}
export default City